﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>采购订单查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData()">
    <!-- 报表标题 -->
    <vue2-report-header :title="'采购订单查询报表'"></vue2-report-header>
    <div style="padding: 10px;" id="queryZone">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item prop='purchaseno' label="采购订单号:">
          <el-autocomplete v-model.trim="queryInfo.purchaseno" placeholder="请输入件号" :trigger-on-focus="false"
            :fetch-suggestions="searchPurchasenoAsync" :value-key="'purchaseno'" :debounce="500" style="width:300px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="件号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入件号" :trigger-on-focus="false"
            :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500" style="width:300px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData" :loading="loading">查询
          </el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="采购订单号" prop="purchaseno"></el-table-column>
        <el-table-column label="采购数量" prop="qty" width="100"></el-table-column>
        <el-table-column label="零件号" prop="productname"></el-table-column>
        <el-table-column label="零件名称" prop="productdesc"></el-table-column>
        <el-table-column label="零件版本" prop="productrevision" width="80"></el-table-column>
        <el-table-column label="供应商名称" prop="vendorname" width="130"></el-table-column>
        <el-table-column label="供应商编号" prop="vendorno" width="130"></el-table-column>
        <el-table-column label="工序" prop="workflowstepname"></el-table-column>
        <el-table-column label="加工分厂" prop="mes_factoryname"></el-table-column>
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope" v-if="scope.row.status">
            <el-tag v-if="scope.row.status === 1" type="success">有效</el-tag>
            <el-tag v-else="scope.row.status === 2" type="danger">无效</el-tag>
          </template>
        </el-table-column>
        </el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[20,100,500]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getWorkerList, getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { purchaseno: '', productname: '', currentPage: 1, pageSize: 20 },
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询采购订单号
        searchPurchasenoAsync(value, callback) {
          fetchSuggestion({ actionName: 'getPurchasenoAsync', name: 'purchaseno', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        //查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ErpPurchaseMfgorderReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 导出
        async getExportExcel() {
          const config = {
            url: '../handler/report/ErpPurchaseMfgorderReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>